﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ImgTianJia</title>
    <script src="~/Scripts/jquery-3.5.1.js"></script>
    <script src="~/Scripts/jquery.validate.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <link rel="stylesheet" type="text/css" href="~/lib/layui-v2.5.6/layui/css/layui.css" />
    <script src="~/lib/layui-v2.5.6/layui/layui.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <div>
        @using (Ajax.BeginForm("ImgTianJia", "Shop", new AjaxOptions { OnSuccess = "addComp" }))
        {

            <input type="hidden" name="ShopId" lay-verify="required" autocomplete="off" class="layui-input" value="@ViewBag.pro">
            <input type="hidden" name="Cont"  lay-verify="required" autocomplete="off" class="layui-input" value="1">

            <div class="layui-form-item">
                <label class="layui-form-label">图片路径</label>
                <div class="layui-input-block">
                    <input id="uploadImg" type="file" name="file1">
                    <input id="photoUrl" name="PicUrl" type="hidden" />
                    <input id="MainPicUrl" name="PicUrl" type="hidden" />
                </div>
                <div class="layui-input-block">
                    <img id="imgPhoto" class="layui-upload-img" style="width:180px; height:140px" />
                </div>
            </div>

            <div class="layui-input-block">
                <button button class="layui-btn" lay-submit lay-filter="formDemo">确定</button>
            </div>
        }
    </div>
    <script>
        layui.use(['form', 'layer', 'laydate', 'upload', 'layedit'], function () {
            var upload = layui.upload;
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var uploadInst = upload.render({
                elem: '#uploadImg' //绑定元素
               , url: '/Shop/UploadPhoto' //上传接口
               , done: function (res) {
                   //上传完毕回调
                   if (res.success) {
                       $("#photoUrl").val(res.remark);
                       $("#imgPhoto").attr("src", "~/" + res.remark);
                       $("#MainPicUrl").val(res.remark);
                       layer.msg("上传成功");
                   }
                   else {
                       layer.msg("上传失败");
                   }
               }
            })
        });
        function addComp(re) {
            if (re) {
                parent.layer.msg(re.msg);
                parent.layui.$("#chaxun").click();
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            } else {
                layer.msg(re.msg);
            }
        }
    </script>

</body>
</html>
